#include <iostream>
#include <algorithm>

using namespace std;
const int N = 100010;
int q[N];
int a[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
    }

    int len = 0;
    q[0] = 2e-9;
    for (int i = 0; i < n; ++i)
    {
        int l = 0, r = len;
        while (l < r)
        {
            int mid = (l + r + 1) >> 1;
            if (q[mid] < a[i]) // 找比a[i]小的第一个数的长度
            {
                l = mid;
            }
            else
            {
                r = mid - 1;
            }
        }
        len = max(len, r + 1); //更新长度
        q[r + 1] = a[i];  //更新此长度的最小值
    }
    printf("%d", len);
    return 0;
}